package cn.wtg.kotlinlib.bindingAdapter

import android.text.TextWatcher
import android.widget.EditText
import androidx.databinding.BindingAdapter

/**
 * author: wtg
 * time: 2022/12/14
 * desc: 输入框dataBinding adapter
 */
object EditTextBindingAdapter {
    /**
     * 设置editText 控件的监控监听
     *
     * @param editText          editText
     * @param binding_textWatcher 监听
     */
    @JvmStatic
    @BindingAdapter(value = ["binding_textWatcher"])
    fun onEditTextCommand(editText: EditText, binding_textWatcher: TextWatcher) {
        editText.addTextChangedListener(binding_textWatcher)
    }

    /**
     * 设置光标在最后
     * @param editText editText
     * @param binding_setSelection 长度
     */
    @JvmStatic
    @BindingAdapter(value = ["binding_setSelection"], requireAll = false)
    fun setSelection(editText: EditText, binding_setSelection: Int) {
        editText.setSelection(binding_setSelection)
    }
}